package com.t8;

/**
 * Created by xuyiwei on 2018/7/19.
 */
class Grain {
    public String toString() { return "Grain"; }
}

class Wheat extends Grain {
    public String toString() { return "Wheat"; }
}

class Mill {
    Grain process() { return new Grain(); }
}

class WheatMill extends Mill {
    Wheat process() {
        System.out.println("1111");
        return new Wheat(); }
}

public class CovariantReturn {
    public static void main(String[] args) {
        Mill m = new Mill();
        Grain g = m.process();
        System.out.println(g);
        m = new WheatMill();
        //虽然方法调用的Mill的  但是以new的对象为准  因此还是走的WheatMill的方法
        Wheat w = (Wheat) m.process();
        System.out.println(w);
        /**
         * output
         * Grain
         * 1111
         * Wheat
         */
    }
}